package com.axdoc.service;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;

public class TagsUserDoctorLine20180126 {
	public static void main(String[] args) throws IOException {

		File daichuli = new File("/Users/jiangboliu/work/files/tags/userDoctorTags002.xls");
		InputStream dinputStream = new FileInputStream(daichuli);
		HSSFWorkbook dxssfWorkbook = new HSSFWorkbook(dinputStream);
		HSSFSheet dsheet1 = dxssfWorkbook.getSheetAt(0);
		
		int i=dsheet1.getLastRowNum();
		int j=dsheet1.getLastRowNum();
		int z=0;
		while (z<j) {
			z++;
			System.out.println(z);
			Row row=dsheet1.getRow(z);
			
			if(row==null||row.getPhysicalNumberOfCells()<2) {
				continue;
			}
			String diseaseStr=row.getCell(0).getStringCellValue();
			String illnessStr=row.getCell(1).getStringCellValue();
			if(diseaseStr.contains(",")) {
				String[] strs=diseaseStr.split(",");
				row.getCell(0).setCellValue(strs[0]);
				i++;
				HSSFRow addRow = dsheet1.createRow(i);
				HSSFCell c=addRow.createCell(0);
				c.setCellValue(strs[1]);
				HSSFCell c1=addRow.createCell(1);
				c1.setCellValue(illnessStr);
				HSSFCell c2=addRow.createCell(2);
				c2.setCellValue(row.getCell(2).getStringCellValue());
			
			}
			
			if(diseaseStr.contains("、")) {
				String[] strs=diseaseStr.split("、");
				row.getCell(0).setCellValue(strs[0]);
				i++;
				HSSFRow addRow = dsheet1.createRow(i);
				HSSFCell c=addRow.createCell(0);
				c.setCellValue(strs[1]);
				HSSFCell c1=addRow.createCell(1);
				c1.setCellValue(illnessStr);
				HSSFCell c2=addRow.createCell(2);
				c2.setCellValue(row.getCell(2).getStringCellValue());
			
			}
		}
		
		 FileOutputStream out = new FileOutputStream("/Users/jiangboliu/work/files/tags/userDoctorTags003.xls");
		 dxssfWorkbook.write(out);
	}
}
